<%--
  Created by IntelliJ IDEA.
  User: 16398
  Date: 2020/7/15
  Time: 13:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<span style="font-size:18px;">
<html>
<head>
    <title>首页</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="approvalProcess/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="approvalProcess/css/commonly-used-show.css" />
    <script type="text/javascript" src="approvalProcess/js/jquery.min.js"></script>
    <script type="text/javascript" src="approvalProcess/js/bootstrap.js" ></script>
    <script type="text/javascript" src="approvalProcess/js/jquery.cookie.js"></script>

    <style>
        .newsdiv{
            border: 1px solid black;
            margin: 30px auto;
            height: 150px;
            padding: 40px;
            border-radius: 5px;
        }
    </style>

</head>
<body class="mybody">

<jsp:include page="theTopMenuDoorkeeper.jsp" />

<div class="container-fluid">
    <div class="row">
        <div class="col-md-2">
            <div class="text-center" id="left-content">
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/doorkeeper" class="list-group-item active">首页</a>
                </div>
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/myDoorkeeperApplication?type=4" class="list-group-item">进出校统计</a>
                    <a href="${pageContext.request.contextPath}/latestNews" class="list-group-item">校园资讯</a>
                    <a href="${pageContext.request.contextPath}/myMessagePush" class="list-group-item">我的通知</a>
                </div>
                <div class="list-group">
                    <a href="${pageContext.request.contextPath}/assistance" class="list-group-item">留言联系</a>
                </div>
            </div>
        </div>

        <section class="content container-fluid">

           <div style="margin-left: 20%; margin-right: 7%; margin-top: 10px;  border: 2px solid #f10732; border-radius: 10px;" class="frame">
                <div style="padding: 10px;" class="text-center">
                    <a href="${pageContext.request.contextPath}/myMessagePush">您共有<span id="my_message"></span>条新的通知，请注意查收！</a>
                </div>
            </div>

            <div style="margin-left: 20%; margin-right: 7%; margin-top: 20px; margin-bottom: 50px; border: 1px solid #6caed4; border-radius: 5px;" class="frame">


                <div style="margin-left: 60px; margin-top: 20px;">
                    <a href="${pageContext.request.contextPath}/latestNews">加载更多></a>
                </div>

                 <div id="my_news" style="margin-left: 60px; margin-right: 60px;">
                 </div>

                <div style="margin-top: 20px;">
                    <span id="user_messge" style="font-size:10px; color: red;"></span>
                </div>
            </div>

        </section>

    </div>

</div>

<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }

    window.onload = function(){
        newsInfo();
        messageInfo();
    }

    function messageInfo(){
        var postUrl = "${pageContext.request.contextPath}/selectMessageNumber";
        var str = {
            "receivedId": userdt.result.id,
            "previewState": "1"
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    $("#my_message").text(0);
                }else {
                    $("#my_message").text(data.result);
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });

    }

    function newsInfo(){
        var postUrl = "${pageContext.request.contextPath}/selectNewsAll";

        var str = {
            "pageResult": {
                "currentPage": 1,
                "pageSize": 3
            }
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    $("#user_messge").text(data.msg);

                }else {

                    var strtab = "";
                    //清空表格数据
                    $("#my_news").html("");

                    var conter = 1;
                    for (var i = 0; i < data.result.items.length; i++) {

                        var title = "";
                        if (data.result.items[i].newsTitle.length > 30){
                            title = data.result.items[i].newsTitle.slice(0,30) + "......";
                        }else {
                            title = data.result.items[i].newsTitle;
                        }

                        strtab = "<div class='newsdiv alert alert-info'>" +
                            "<div style='float: left; margin-left: 10px;'>" +
                            "<a href='${pageContext.request.contextPath}/advisoryDetails?id=" + data.result.items[i].id + "' >" +
                            "<span>" + title + "</span>" +
                            "</a>" +
                            "<p style='margin-top: 20px'>" +
                            "<span>" + "发布者：" + data.result.items[i].newsIssuer + "</span>" +
                            "<span style='margin-left: 200px;'>" + "发布时间：" + data.result.items[i].createTime + "</span>" +
                            "</p>" +
                            "</div>" +
                            "<div style='float: right; '>" +
                            "<a class='btn btn-default btn-sm' href='${pageContext.request.contextPath}/advisoryDetails?id=" + data.result.items[i].id + "'>查看详情>></a>" +
                            "</div>" +
                            "</div>"
                        ;

                        $("#my_news").append(strtab);//将数据追加

                        conter++;
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>